//
//  BDTaocanTableViewCell.m
//  BadBoy
//
//  Created by wen on 2017/3/16.
//  Copyright © 2017年 com.8xiong. All rights reserved.
//

#import "BDTaocanTableViewCell.h"

@interface BDTaocanTableViewCell ()

@property (nonatomic, strong) UIButton *shenqingButton;

@property (nonatomic, strong) UIImageView *coverImageView;
@property (nonatomic, strong) UILabel *nickLabel;
@property (nonatomic, strong) UIButton *rightButton;

@property (nonatomic, copy) void(^buttonClick)();

@property (nonatomic, assign) NSInteger status;

@end

@implementation BDTaocanTableViewCell

+ (CGFloat)getCellHeightWithModel:(id)model{
    return 60;
}

- (void)configeWithManager:(BDShopManagerModel *)manager shenqingStatus:(NSInteger)status buttonClick:(void(^)())buttonClick{
    if (manager== nil) {
        self.shenqingButton.hidden = NO;
        self.coverImageView.hidden = YES;
        self.nickLabel.hidden = YES;
        self.rightButton.hidden = YES;
    }else{
        self.shenqingButton.hidden = YES;
        self.coverImageView.hidden = NO;
        self.nickLabel.hidden = NO;
        self.rightButton.hidden = NO;
        
        [self.coverImageView sd_setImageWithURL:[NSURL URLWithString:manager.cover] placeholderImage:[UIImage imageNamed:@"avatar"]];
        self.nickLabel.text = manager.name;
    }
    self.buttonClick = buttonClick;
    self.status = status;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    self.shenqingButton.size = CGSizeMake(140, 36);
    self.shenqingButton.center = CGPointMake(self.width / 2.0, self.height / 2.0);
    
    NSString *title = nil;
    if (self.status == -1 || self.status == 2) {
        title = ASLocalizedString(@"申请该店经理");
    }else if (self.status == 0) {
        title = ASLocalizedString(@"正在等待审核");
    }else if (self.status == 1) {
        title = ASLocalizedString(@"申请已通过");
    }else if (self.status == 3) {
        title = ASLocalizedString(@"不能申请");
    }
    
    [self.shenqingButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.shenqingButton setTitle:title forState:UIControlStateNormal];
    self.shenqingButton.titleLabel.font = [UIFont systemFontOfSize:17];
    self.shenqingButton.backgroundColor = [UIColor colorWithHexString:@"#cccccc"];
    
    self.shenqingButton.layer.masksToBounds = YES;
    self.shenqingButton.layer.cornerRadius = 4;
    if (self.status >= 0) {
        self.shenqingButton.userInteractionEnabled = NO;
    }else{
        self.shenqingButton.userInteractionEnabled = YES;
    }
    
    self.coverImageView.size = CGSizeMake(40, 40);
    self.coverImageView.left = 10;
    self.coverImageView.centerY = self.height / 2.0;
    
    self.nickLabel.textColor = [UIColor colorWithHexString:@"#111111"];
    self.nickLabel.font = [UIFont systemFontOfSize:15];
    self.nickLabel.left = self.coverImageView.right + 10;
    self.nickLabel.height = 20;
    self.nickLabel.centerY = self.coverImageView.centerY;
    
    self.nickLabel.width = [self.nickLabel.text widthWithFont:self.nickLabel.font];

//    self.rightButton.image = [UIImage imageNamed:@"righ"];
}

- (void)shenqingButtonAciton{
    self.buttonClick();
}

- (UIButton *)shenqingButton{
    if (!_shenqingButton) {
        self.shenqingButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_shenqingButton addTarget:self action:@selector(shenqingButtonAciton) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_shenqingButton];
    }
    return _shenqingButton;
}

- (UIImageView *)coverImageView{
    if (!_coverImageView) {
        self.coverImageView= [[UIImageView alloc] init];
        [self addSubview:_coverImageView];
    }
    return _coverImageView;
}

- (UILabel *)nickLabel{
    if (!_nickLabel) {
        self.nickLabel = [[UILabel alloc] init];
        [self addSubview:_nickLabel];
    }
    return _nickLabel;
}

@end
